Skip to content

Comments

gate: fix script context leakage and empty envelope parsing#56

Merged
davidahmann merged 1 commit intomainfrom
codex/fix-gate-context-and-envelope-parsing
Feb 20, 2026
Merged

gate: fix script context leakage and empty envelope parsing#56
davidahmann merged 1 commit intomainfrom
codex/fix-gate-context-and-envelope-parsing

Conversation

@davidahmann
Copy link
Collaborator

Problem

Recent review findings identified three correctness gaps in Gate:

  • script-step Wrkr enrichment could leak wrkr.* context across steps due to shared auth_context map references.
  • approved-script registry parser rejected valid empty envelope payloads ({"entries":[]}).
  • Wrkr inventory parser rejected valid empty envelope payloads ({"items":[]}).

These can produce incorrect policy matches and fail-closed blocks for syntactically valid configs.

Changes

  • core/gate/policy.go
    • clone per-step auth context before ApplyWrkrContext in script evaluation to isolate step-local context mutations.
  • core/gate/approved_scripts.go
    • accept envelope-form registry payloads whenever entries key is present, including empty arrays.
  • core/gate/context_wrkr.go
    • accept envelope-form Wrkr payloads whenever items key is present, including empty arrays.
  • Added regression tests:
    • core/gate/policy_test.go: no Wrkr context leakage across script steps.
    • core/gate/approved_scripts_test.go: empty registry envelope parses as empty set.
    • core/gate/context_wrkr_test.go: empty Wrkr envelope parses as empty set.

Validation

  • make prepush-full
  • ./gait doctor --json
  • go test ./core/gate
  • go test ./cmd/gait -run "GateEval|ApproveScript|ListScripts"
  • bash scripts/run_scenarios.sh gait
  • bash scripts/test_script_intent_acceptance.sh ./gait

@davidahmann davidahmann merged commit 51a33f9 into main Feb 20, 2026
7 checks passed
@davidahmann davidahmann deleted the codex/fix-gate-context-and-envelope-parsing branch February 20, 2026 02:55
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bd755ba0cc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +101 to +104
if err := json.Unmarshal(rawItems, &wrapped.Items); err != nil {
return nil, fmt.Errorf("parse wrkr inventory: %w", err)
}
entries = wrapped.Items

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Validate items is an array in Wrkr envelope

This branch now accepts {"items":null} because unmarshalling null into a slice succeeds and yields nil, so malformed inventory payloads are treated as an empty inventory instead of an error. In cmd/gait/gate.go, high-risk/oss-prod fail-closed behavior for --wrkr-inventory is only triggered when LoadWrkrInventory returns an error, so this allows a broken inventory file to silently disable wrkr.* context enrichment and can cause context-based block rules to be skipped.

Useful? React with 👍 / 👎.

Comment on lines +184 to +187
if err := json.Unmarshal(rawEntries, &envelope.Entries); err != nil {
return nil, fmt.Errorf("parse approved script registry: %w", err)
}
return normalizeApprovedScriptEntries(envelope.Entries)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Validate entries is an array in registry envelope

This parsing path also treats {"entries":null} as valid because unmarshalling null into a slice returns no error, so invalid registry content is silently normalized to an empty set. cmd/gait/gate.go only enters its fail-closed path for configured approved-script registries when ReadApprovedScriptRegistry returns an error, so malformed registry state no longer surfaces as an unavailable/invalid registry in high-risk or oss-prod contexts.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant